/*
****************************************************************************************
*     Coder :         Allen
****************************************************************************************
*/

#ifndef	__MCUPERIPHERAL_H_
#define	__MCUPERIPHERAL_H_



#if 1
sbit IO_RC522_RST = P2 ^ 1;
sbit IO_RC522_SCK = P2 ^ 4;
sbit IO_RC522_NSS = P2 ^ 5;
sbit IO_RC522_SI = P2 ^3;
sbit IO_RC522_SO = P2 ^ 2;
#elif 0		//MTK
sbit IO_RC522_RST = P3 ^ 4;
sbit IO_RC522_SCK = P3 ^ 7;
sbit IO_RC522_NSS = P2 ^ 0;
sbit IO_RC522_SI = P3 ^6;
sbit IO_RC522_SO = P3 ^ 5;
#elif 0
sbit IO_RC522_RST = P1 ^ 4;
sbit IO_RC522_SCK = P1 ^ 6;
sbit IO_RC522_NSS = P1 ^ 7;
sbit IO_RC522_SI = P1 ^5;
sbit IO_RC522_SO = P3 ^ 5;
#elif 0
sbit IO_RC522_RST = P3 ^ 3;
sbit IO_RC522_SCK = P1 ^ 4;
//sbit IO_RC522_IRQ = P0 ^ 1;
sbit IO_RC522_NSS = P5 ^ 4;
sbit IO_RC522_SI = P5 ^5;
sbit IO_RC522_SO = P3 ^ 6;
#else
sbit IO_RC522_RST = P0 ^ 0;
sbit IO_RC522_SCK = P0 ^ 4;
sbit IO_RC522_IRQ = P0 ^ 1;
sbit IO_RC522_NSS = P0 ^ 5;
sbit IO_RC522_SI = P0 ^ 3;
sbit IO_RC522_SO = P0 ^ 2;
#endif

sbit program_check_led = P2 ^ 0;

#define	IntervalOneMs	63543 //64549//(65536 - FOSC/12/1000)

#define T500us	65036//64549//65036

#define BAUD 9600

#define NONE_PARITY  0
#define ODD_PARITY   1
#define EVEN_PARITY  2
#define MARK_PARITY  3
#define SPACE_PARITY 4

#define PARITYBIT NONE_PARITY

#define EEPROM_FUN 1

#if EEPROM_FUN
#define CMD_IDLE 0
#define CMD_READ 1
#define CMD_PROGRAM 2
#define CMD_ERASE 3

#define ENABLE_IAP 0x81

#define EEPROM_START_ADDR 0x0000

#define EEPROM_ADDR_TOTAL_CARD 100

#define EEPROM_SECTION_1_ADDR (EEPROM_START_ADDR+512)

#endif

void uart_send_byte(u8 dat);

void uart_send_debug(u8 a,u8 b,u8 c,u8 d);

void Uart_Send_String(unsigned char *str,unsigned char Len);

void uart2_send_byte(u8 dat);

void uart2_send_string(u8 *str,u8 len);

void SPIInit(void);

void mcu_initial(void);

void delay_ms(unsigned int _ms);

unsigned char EEPROM_ReadByte(unsigned int addr);

void EEPROM_Erase(unsigned int addr);

void EEPROM_WriteByte(unsigned int addr,unsigned char date);

extern void debug_to_read_eeprom(void);

extern void debug_to_read_eeprom_segment(u8 *start_addr, u8 *end_addr);

extern void debug_to_rst_check_eeprom(void);

void _delay_us(unsigned int _us);
void delay_ms(unsigned int _ms);

void program_check(void);


#endif

